#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <bitset>
#include <utility>
using namespace std;

#define mm(a, n) memset(a, n, sizeof a)
#define mk(a, b) make_pair(a, b)

const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

string s, t;
char n[10], f[10];
int m;
int a, b;

// 使用字符串性质，以及sprintf给字符串添加前导零
inline void solution() {
    cin >> m;
    sprintf(n, "%04d", m);
    s = n;

    int diff = 1;
    while (diff != 6174 && diff != 0) {
        sort(s.begin(), s.end(), greater<char>());
        a = stoi(s);
        sort(s.begin(), s.end());
        b = stoi(s);
        diff = a - b;
        sprintf(f, "%04d", diff);
        s = f;
        printf("%04d - %04d = %04d\n", a, b, diff);
    }

}

int main() {
    freopen("input.txt", "r", stdin);
    quickread();
    solution();
    return 0;
}